<?php
/**
 * =============================================================================
 * Class: Tv_Arte_Header
 * Last mod: 21/09/2011 14:40:37
 *
 * Main package Class
 */
class Tv_Arte_Header
{
	/**
	 * Constantes langue
	 * @var String
	 */
	const LANG_FR 			= 'fr';
	const LANG_DE 			= 'de';
	const LANG_EN 			= 'en';
	/**
	 * Constantes type de site
	 * @var String
	 */
	const ARTE_TV 			= 'arte-tv';
	const ARTE_VIDEOS 		= 'arte-videos';
	const ARTE_CREATIVE 	= 'arte-creative';
	const ARTE_LIVE 		= 'arte-live';
	const ARTE_VOD 			= 'arte-vod';
	const ARTE_BOUTIQUE 	= 'arte-boutique';
	const ARTE_RADIO        = 'arte-radio';
	const ARTE_PRO          = 'arte-pro';
	/**
	 * @var String
	 */
	private $_lang 			= self::LANG_FR;
	/**
	 * @var String
	 */
	private $_siteType 		= self::ARTE_TV;
	/**
	 * @var Boolean
	 */
	private $_showLogin 	= true;
		/**
	 * @var Boolean
	 */
	private $_showSocial 	= true;
	/**
	 * @var Boolean
	 */
    private $_showLang 		= true;
    /**
     * @var Array
     */
    private $_config        = Array();
    /**
     * @staticvar   Tv_Arte_Header
     */
    private static $_instance = null;
	/**
	 * @static
	 * @param   Array
	 *	(
	 *  	'lang' => String
	 *  	'siteType' => String
	 *      'showLogin' => Boolean
	 *      'showLang' => Boolean
	 *  )
	 * @return  Tv_Arte_Header
	 */
 	public static function getInstance($params=Array())
 	{
 	    if (is_null(self::$_instance)) {
			self::$_instance = new self($params);
		}
 	    return self::$_instance;
 	}
 	/**
 	 * @static
     * @param   Array
	 *	(
	 *  	'lang' => String
	 *  	'siteType' => String
	 *      'showLogin' => Boolean
	 *      'showLang' => Boolean
	 *  )
 	 * @return  Tv_Arte_Header
 	 */
 	public static function createInstance(Array $params)
 	{
 	    return new self($params);
 	}
	/**
	 * Constructor
	 * @param   Array
	 * @see     Tv_Arte_Header::getInstance()
	 */
	private function __construct($params=Array())
	{
	    $this->_lang = (isset($params['lang']) && in_array($params['lang'], Array(self::LANG_FR, self::LANG_DE, self::LANG_EN), true)) ? $params['lang'] : 'fr';
        Tv_Arte_Header_Translate::setLang($this->_lang);
	    $this->_config = Array(
			self::ARTE_TV => Array(
			    'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_TV . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_arte'),
			    'title' => Tv_Arte_Header_Translate::get('title_arte'),
			    'url' => Tv_Arte_Header_Translate::get('url_arte'),
			    '_metas' => Array(
					'title_key' => 'title_arte',
					'url_key' => 'url_arte',
					'langs' => Array(self::LANG_FR, self::LANG_DE, self::LANG_EN)
				)
			),
			self::ARTE_VIDEOS => Array(
                'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_VIDEOS . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_arte7'),
			    'title' => Tv_Arte_Header_Translate::get('title_arte7'),
			    'url' => Tv_Arte_Header_Translate::get('url_arte7'),
			    '_metas' => Array(
			        'title_key' => 'title_arte7',
					'url_key' => 'url_arte7',
					'langs' => Array(self::LANG_FR, self::LANG_DE, self::LANG_EN)
				)
			),
			self::ARTE_LIVE => Array(
                'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_LIVE . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_arte_live'),
			    'title' => Tv_Arte_Header_Translate::get('title_arte_live'),
			    'url' => Tv_Arte_Header_Translate::get('url_arte_live'),
			    '_metas' => Array(
			        'title_key' => 'title_arte_live',
					'url_key' => 'url_arte_live',
					'langs' => Array(self::LANG_FR, self::LANG_DE, self::LANG_EN)
				)
			),
			self::ARTE_CREATIVE => Array(
                'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_CREATIVE . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_creative'),
			    'title' => Tv_Arte_Header_Translate::get('title_creative'),
			    'url' => Tv_Arte_Header_Translate::get('url_creative'),
			    '_metas' => Array(
			        'title_key' => 'title_creative',
					'url_key' => 'url_creative',
					'langs' => Array(self::LANG_FR, self::LANG_DE, self::LANG_EN)
				)
			),
			self::ARTE_RADIO => Array(
                'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_RADIO . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_radio'),
			    'title' => Tv_Arte_Header_Translate::get('title_radio'),
			    'url' => Tv_Arte_Header_Translate::get('url_radio'),
			    '_metas' => Array(
			        'title_key' => 'title_radio',
					'url_key' => 'url_radio',
					'langs' => Array(self::LANG_FR, self::LANG_DE, self::LANG_EN)
				)
	        ),
			self::ARTE_VOD => Array(
                'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_VOD . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_vod'),
			    'title' => Tv_Arte_Header_Translate::get('label_vod'),
			    'url' => Tv_Arte_Header_Translate::get('url_vod'),
			    '_metas' => Array(
			        'title_key' => 'title_vod',
					'url_key' => 'url_vod',
					'langs' => Array(self::LANG_FR, self::LANG_DE, self::LANG_EN)
				)
			),
			self::ARTE_BOUTIQUE => Array(
                'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_BOUTIQUE . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_boutique'),
			    'title' => Tv_Arte_Header_Translate::get('title_boutique'),
			    'url' => Tv_Arte_Header_Translate::get('url_boutique'),
			    '_metas' => Array(
			        'title_key' => 'title_boutique',
					'url_key' => 'url_boutique',
					'langs' => Array(self::LANG_FR, self::LANG_DE, self::LANG_EN)
				)
			),
            self::ARTE_PRO => Array(
                'logo' => Tv_Arte_Header_Env::get('root_http') . '/assets/img/' . self::ARTE_PRO . '.png',
			    'label' => Tv_Arte_Header_Translate::get('label_pro'),
			    'title' => Tv_Arte_Header_Translate::get('title_pro'),
			    'url' => Tv_Arte_Header_Translate::get('url_pro'),
			    '_metas' => Array(
			        'title_key' => 'title_pro',
					'url_key' => 'url_pro',
					'langs' => Array(self::LANG_FR, self::LANG_DE)
				)
			)
	    );
	    if (!isset($params['siteType'])) {
	        throw new Tv_Arte_Header_Exception('siteType is not defined');
	    } else if (!isset($this->_config[$params['siteType']])) {
            throw new Tv_Arte_Header_Exception('siteType ' . $params['siteType'] . ' does not exist');
		} else if (!in_array($this->_lang, $this->_config[$params['siteType']]['_metas']['langs'], true)) {
		    throw new Tv_Arte_Header_Exception('Lang  ' . $this->_lang . ' does not exist for site type ' . $params['siteType']);
		} else {
		    $this->_siteType = $params['siteType'];
            $this->_config[$this->_siteType]['selected'] = true;
            $this->_showLang = (isset($params['showLang']) && 'true' == $params['showLang']);
            $this->_showLogin = (isset($params['showLogin']) && 'true' == $params['showLogin']);
            $this->_showSocial = (isset($params['showSocial']) && 'true' == $params['showSocial']);
	    }
	}
 	/**
	 * @return  String
	 */
	public function getLang()
	{
	    return $this->_lang;
	}
	/**
	 * @return  Array
	 */
	public function getConfig()
	{
	    return $this->_config;
	}
	/**
	 * @return  Boolean
	 */
	public function getShowLang()
	{
	    return $this->_showLang;
	}
	/**
	 * @return  Boolean
	 */
	public function getShowLogin()
	{
		return $this->_showLogin;
	}
 	/**
	 * @return  Boolean
	 */
	public function getShowSocial()
	{
		return $this->_showSocial;
	}
	/**
	 * @return  Array
	 */
	public function getCurrent()
	{
	    return $this->_config[$this->_siteType];
	}
	/**
	 * @return  Array
	 */
	public function getLanguages()
	{
	    $languages = Array();
	    foreach (Array(self::LANG_FR, self::LANG_DE, self::LANG_EN) as $v) {
	        if (in_array($v, $this->_config[$this->_siteType]['_metas']['langs'], true)) {
	            $languages[$v] = Array(
	                'label' => Tv_Arte_Header_Translate::get('lang_label', $v),
					'url' => Tv_Arte_Header_Translate::get($this->_config[$this->_siteType]['_metas']['url_key'], $v)
	            );
	        }
	    }
		$languages[$this->_lang]['selected'] = true;
		return $languages;
	}
}